package com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.util;

import java.lang.reflect.Field;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

public class CommonUtil {

	/**
	 * 属性复制
	 * 
	 * @param dest
	 * @param orig
	 * @throws Exception
	 */
	public static void propertyCopy(Object dest, Object orig) throws Exception {
		Field[] fields = orig.getClass().getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			String name = fields[i].getName();
			if (PropertyUtils.isReadable(orig, name) && PropertyUtils.isWriteable(dest, name)) {
				Object value = PropertyUtils.getSimpleProperty(orig, name);
				if (value != null) {
					PropertyUtils.setSimpleProperty(dest, name, value);
				}
			}
		}
	}

	/**
	 * 属性复制
	 * 
	 * @param dest
	 * @param orig
	 * @throws Exception
	 */
	public static void propertyCopyForMap(Map<String, Object> dest, Object orig) throws Exception {
		Field[] fields = orig.getClass().getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			String name = fields[i].getName();
			if (PropertyUtils.isReadable(orig, name)) {
				Object value = PropertyUtils.getSimpleProperty(orig, name);
				if (value != null) {
					dest.put(name, value);
				}
			}
		}
	}

}
